<template>
	<view class="index">
		<musichead title='网易云音乐' :icon='false'></musichead>
		<view class="container">
			<scroll-view scroll-y="true">
				<!-- 搜索框 -->
				<view class="index-search" @tap="handleToSearch">
					<text class="iconfont icon-fangdajing"></text>
					<input type="text" placeholder="搜索歌曲" />
				</view>
				<!-- 骨架屏 -->
				<view v-if="isLoading">
					<m-for-skeleton :avatarSize="200" :row="3" :loading="isLoading" isarc="square"
						v-for="(item,key) in 4" :title="false" :titleStyle={} :key="key">
					</m-for-skeleton>
				</view>

				<!-- 歌曲列表 -->
				<view class="index-list" v-else>
					<view class="index-list-item" v-for="(item,index) in topList" :key='item.id'
						@tap="handleToList(item.id)">
						<!-- 左侧图片渲染 -->
						<view class="index-list-img">
							<image :src="item.coverImgUrl" mode=""></image>
							<text>{{item.updateFrequency}}</text>
						</view>
						<!-- 右侧文字排列 -->
						<view class="index-list-text">
							<view v-for="(item1,index1) in item.tracks" :key='item1.first'>{{index1+1}}.{{item1.first}}
								- {{item1.second}}
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import musichead from '@/components/musichead/musichead.vue'
	//引入骨架屏插件
	import mForSkeleton from "@/components/m-for-skeleton/m-for-skeleton"
	import {
		topList
	} from '@/common/api.js'
	export default {
		data() {
			return {
				topList: [],
				isLoading: true
			}
		},
		components: {
			musichead,
			mForSkeleton
		},
		onLoad() {
			topList().then(res => {
				if (res.length) {
					setTimeout(() => {
						this.topList = res
						this.isLoading = false
					}, 500)

					
				}
			})
		},
		methods: {
			handleToList(id) {
				uni.navigateTo({
					url: '/pages/list/list?id=' + id
				})
			},
			handleToSearch() {
				uni.navigateTo({
					url: '/pages/search/search'
				})
			}
		}
	}
</script>

<style scoped>
	.index {}

	.index-search {
		display: flex;
		align-items: center;
		height: 80rpx;
		margin: 10rpx 30rpx 30rpx 30rpx;
		background: #f7f7f7;
		border-radius: 50rpx;
	}

	.index-search text {
		font-size: 26rpx;
		margin-left: 28rpx;
		margin-right: 26rpx;
	}

	.index-search input {
		font-size: 28rpx;
		flex: 1;
	}

	.index-list {
		margin: 0 30rpx;
	}

	.index-list-item {
		display: flex;
		margin-bottom: 34rpx;
	}

	.index-list-img {
		width: 212rpx;
		height: 212rpx;
		position: relative;
		border-radius: 30rpx;
		overflow: hidden;
		margin-right: 22rpx;
	}

	.index-list-img image {
		width: 100%;
		height: 100%;
	}

	.index-list-img text {
		position: absolute;
		left: 12rpx;
		bottom: 16rpx;
		color: #ffffff;
		font-size: 20rpx;
	}

	.index-list-text {
		font-size: 24rpx;
		line-height: 66rpx;
		align-items: center;

	}

	.index-list-text view {
		width: 55vw;
		/* 只在一行显示，多出省略 */
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
</style>
